<%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2020/9/28
  Time: 14:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>村花</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/Apage/layui/css/layui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/Apage/css/home.css">
</head>
<body >
<!-- 搜索条件开始 -->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>查询条件</legend>
</fieldset>
<form class="layui-form" method="post" id="searchFrm">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">登录名称:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="aname" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入登录名称" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">登录IP:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="logip" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入登录IP" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">开始时间:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="starttime" id="starttime" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入开始时间" style="height: 30px;border-radius: 10px">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">结束时间:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="endtime" id="endtime" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入结束时间" style="height: 30px;border-radius: 10px">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-black" style="text-align: center">
            <button   class="layui-btn layui-btn-normal layui-icon layui-icon-search layui-btn-radius layui-btn-sm" lay-submit  lay-filter="doSearch">查询
            </button>
            <button type="reset" class="layui-btn layui-btn-warm layui-icon layui-icon-refresh layui-btn-radius layui-btn-sm">重置
            </button>
        </div>
    </div>

</form>
<!-- 搜索条件结束 -->
<table id="logTable" lay-filter="logTable"></table>

<script id="toolbarlog" type="text/html">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="delBatch">批量删除</button>
    </div>
</script>

<script id="barlog" type="text/html">
    <a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-radius" lay-event="del">删除</a>
</script>




<script type="text/javascript" src="${pageContext.request.contextPath}/static/layui/layui.js"></script>

<script>
    var roleTable
    var tab;
    var index;
    layui.use(['table','form','layer','jquery' ,'laydate'],function() {
        var table = layui.table;
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;
        var laydate = layui.laydate;
        //给日期框赋值
        laydate.render({
            elem:'#starttime'
            ,type:'datetime'
        });
        laydate.render({
            elem:'#endtime'
            ,type:'datetime'
        });
        tab = table.render({
            elem : '#logTable'
            , url : "${pageContext.request.contextPath}/log/findLog"
            , cellMinWidth: 30
            , page :{limit:5,limits:[5,10,15,20]}
            , toolbar:'#toolbarlog'//开启头部工具栏，并为其绑定左侧模板
            ,title: '菜单数据表'
            , cols: [
                [
                {type: 'checkbox', fixed: 'left'}
                ,{field:'id', title: '日志ID',fixed:'center'}
                ,{field:'aname', title: '登录名称', fixed:'center'}
                ,{field:'logip',  title: 'IP地址',fixed:'center'}
                ,{field:'logtime', title: '登录时间',fixed:'center'}
                ,{fixed: 'right', title:'操作', toolbar: '#barlog', width:260}
                ]
            ]

        })


        // form表单提交  -- 查询功能
        form.on("submit(doSearch)", function (data) {
            // ajax查询数据
            tab.reload({
                <%--url: "${pageContext.request.contextPath}/log/findLog?" + $("#searchFrm").serialize()--%>
                <%--, page: {curr: 1}--%>
                where:data.field,
                page:{curr:1}
            })

            // 不跳转页面
            return false;
        })





        function delchekAll(obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data1=checkStatus.data
            var ids=""
            for(var i=0;i<data1.length;i++){
                if(i==data1.length-1){
                    ids+=data1[i].id
                }else{
                    ids+=data1[i].id+","
                }
            }

            if(data1.length=="0"){
                layer.msg("请至少选中一条数据")
                return false;
            }
            layer.confirm("确定要删除"+data1.length+"条数据吗?",function () {
                $.get("${pageContext.request.contextPath}/log/delAll",{"ids":ids},function (r) {
                    tab.reload()
                    layer.msg(r.msg)
                })
            })
        }




        //监听行工具事件
        table.on('tool(logTable)', function(obj){
            var data = obj.data
            if(obj.event == "del"){ // 删除
                logDelete(data.id)
            }

        })

        function logDelete(deleteById) {

            layer.confirm("确定删除该数据么？",function () {
                // 1. 该菜单是否有子菜单
                $.post("${pageContext.request.contextPath}/log/checkExitChildren",{"id":deleteById},function (r) {
                    if(r.data == 0){
                        // 有子菜单， 不能删除
                        layer.msg("不能删除")

                    }else{
                        $.post("${pageContext.request.contextPath}/log/deletelog",{"id":deleteById},function (rr) {
                            layer.msg(rr.msg)
                            tab.reload()

                        })
                    }
                })


            })
        }

    })



</script>
</body>
</html>
